package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.domain.GlueSplice;
import com.ruoyi.system.mapper.GlueSpliceMapper;
import com.ruoyi.system.service.IGlueCategoryService;
import com.ruoyi.system.service.IGlueSpliceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * 粘接接头信息Service业务层处理
 *
 * @author ruoyi
 * @date 2025-03-31
 */
@Service
public class GlueSpliceServiceImpl extends ServiceImpl<GlueSpliceMapper,GlueSplice> implements IGlueSpliceService
{
    @Autowired
    private GlueSpliceMapper glueSpliceMapper;

    @Autowired
    private IGlueCategoryService glueCategoryService;

    /**
     * 查询粘接接头信息
     *
     * @param id 粘接接头信息主键
     * @return 粘接接头信息
     */
    @Override
    public GlueSplice selectGlueSpliceById(Long id)
    {
        return glueSpliceMapper.selectGlueSpliceById(id);
    }

    /**
     * 查询粘接接头信息列表
     *
     * @param glueSplice 粘接接头信息
     * @return 粘接接头信息
     */
    @Override
    public List<GlueSplice> selectGlueSpliceList(GlueSplice glueSplice)
    {
        //有值就递归查出所有子集
        if (!ObjectUtils.isEmpty(glueSplice.getClassifyId())){
            List<Long> ids = glueCategoryService.getIds(glueSplice.getClassifyId());
            glueSplice.setClassifyIds(ids);
        }

        return glueSpliceMapper.selectGlueSpliceList(glueSplice);
    }

    /**
     * 新增粘接接头信息
     *
     * @param glueSplice 粘接接头信息
     * @return 结果
     */
    @Override
    public int insertGlueSplice(GlueSplice glueSplice)
    {
        glueSplice.setCreateTime(DateUtils.getNowDate());
        glueSplice.setCreateBy(SecurityUtils.getUserId().toString());
        return glueSpliceMapper.insertGlueSplice(glueSplice);
    }

    /**
     * 修改粘接接头信息
     *
     * @param glueSplice 粘接接头信息
     * @return 结果
     */
    @Override
    public int updateGlueSplice(GlueSplice glueSplice)
    {
        glueSplice.setUpdateTime(DateUtils.getNowDate());
        return glueSpliceMapper.updateGlueSplice(glueSplice);
    }

    /**
     * 批量删除粘接接头信息
     *
     * @param ids 需要删除的粘接接头信息主键
     * @return 结果
     */
    @Override
    public int deleteGlueSpliceByIds(Long[] ids)
    {
        return glueSpliceMapper.deleteGlueSpliceByIds(ids);
    }

    /**
     * 删除粘接接头信息信息
     *
     * @param id 粘接接头信息主键
     * @return 结果
     */
    @Override
    public int deleteGlueSpliceById(Long id)
    {
        return glueSpliceMapper.deleteGlueSpliceById(id);
    }


    /**
     * 粘接接头涉及产品三级目录
     * @param dto
     * @return
     */
    @Override
    public List<String> getModel(String dto) {
        return glueSpliceMapper.getModel(dto);

    }
}
